package health.lm.com.shop.adapter;

import android.annotation.SuppressLint;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jakewharton.rxbinding2.view.RxView;
import com.vondear.rxtool.RxTimeTool;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.router.ARouterConstant;
import health.lm.com.shop.R;
import health.lm.com.shop.entity.HLPeopleEntity;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.adapter
 * Date：2019/8/8 11:04
 * Introduce：我的人脉
 */
public class HLPeopleAdapter extends BaseQuickAdapter<HLPeopleEntity, BaseViewHolder> {
    /*1、商会会员列表*/
    private int type = 0;

    public HLPeopleAdapter(@Nullable List<HLPeopleEntity> data) {
        super(R.layout.hl_activity_people_item, data);
    }

    public HLPeopleAdapter(@Nullable List<HLPeopleEntity> data, int type) {
        super(R.layout.hl_activity_people_item, data);
        this.type = type;
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @SuppressLint("CheckResult")
    @Override
    protected void convert(BaseViewHolder helper, HLPeopleEntity item) {
        String time = RxTimeTool.date2String(new Date(Long.parseLong(item.getTime()) * 1000),
                new SimpleDateFormat("yyyy-MM-dd"));
        ImageLoaderHelper.getInstance().load(mContext, item.getAvatar(), helper.getView(R.id.imageView3));
        helper.setText(R.id.textView4, item.getName())
                .setText(R.id.textView5, item.getPhone())
                .setText(R.id.textView6, "关注时间：" + time)
                .setText(R.id.textView9, item.getDepartment())
                .setGone(R.id.textView9, !TextUtils.isEmpty(item.getDepartment()))
                .setGone(R.id.imageView4, true)
                .setGone(R.id.textView7, false)
                .setGone(R.id.textView8, false)
        ;
        if (type == 1) helper.setGone(R.id.textView6, false);
        RxView.clicks(helper.getView(R.id.imageView4)).throttleFirst(1, TimeUnit.SECONDS).subscribe(v -> {
            ARouter.getInstance().build(ARouterConstant.HLChatActivity)
                    .withString("id", item.getId() + "")
                    .withString("name", item.getName())
                    .navigation();
        });
    }
}
